package com.test.burnincash.aaahpoppomelo.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.test.burnincash.R;
import com.test.burnincash.aaahpoppomelo.base.BaseActivity_hpoppomelo;
import com.test.burnincash.aaahpoppomelo.bean.UserData_hpoppomelo;
import com.test.burnincash.util_burnin.StringUtil_burnin;

public class CustomerManagementActivity_hpoppomelo extends BaseActivity_hpoppomelo {

    private LinearLayout groupLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_customer_management_hpoppomelo);
        init();
    }

    private void init(){

        setBackBtn_burnin(findViewById(R.id.activity_customer_management_ib_back));

        groupLayout = findViewById(R.id.activity_customer_management_layout_group);

        updateCustomers();

    }

    private void updateCustomers(){

        groupLayout.removeAllViews();

        for (String customer:UserData_hpoppomelo.getInstance().getCustomers()){
            showCustomer(customer);
        }

    }

    private void showCustomer(String customer){

        @SuppressLint("InflateParams") View view = LayoutInflater.from(this).inflate(R.layout.item_customer_management_hpoppomelo,null);

        TextView customerTv = view.findViewById(R.id.item_customer_management_tv_customer);
        customerTv.setText(StringUtil_burnin.getSafeString(customer));

        view.findViewById(R.id.item_customer_management_ib_delete).setOnClickListener(v -> {
            UserData_hpoppomelo.getInstance().getCustomers().remove(customer);
            updateCustomers();
        });

        groupLayout.addView(view);

    }

}